<template>
  <div class="register">
      <div class="header">
        <div class="container">
            <span class="inbk">
				<router-link to="/index"><img src="../../../assets/images/logo.png" alt=""></router-link>
			</span>
        </div>
      </div>
      
      <div class="box flex-ct">
        <div class="tab-box">
          <div class="tab-box_item">
            <div class="box-name">{{$t('common.login.bindPhone')}}</div>
            <div class="box-input">
              <input type="text" maxlength="11" name="password" :placeholder="this.$t('common.login.enterPassword')" v-model="user.phone"   @input="check" @blur="check">
            </div>
            <div class="box-des">
              <span class="red_color" v-if="checkStatus==0">{{$t('common.login.jyPhone')}}</span>
              <span class="red_color" v-if="checkStatus==2 && haved">{{$t('common.login.unphone')}}</span>
            </div>
          </div>
          <div class="tab-box_item">
            <div class="box-name">{{$t('common.login.setPassword')}}</div>
            <div class="box-input">
              <input type="password" maxlength="16" name="password" :placeholder="this.$t('common.login.enterNewPassword')" v-model="user.newPwd">
            </div>
            <div class="box-des">
              {{$t('common.company.companytask6')}}
            </div>
          </div>
          <div class="tab-box_item">
            <div class="box-name">{{$t('common.login.code')}}</div>
            <div class="box-input">
              <input type="passsword" width="244" name="code" :placeholder="this.$t('common.login.enterCode')" class="captcha-input" v-model="user.code">
              <button type="button" width="122" class="captcha-btn" @click="sendCode" v-if="isSendCode">{{$t('common.login.getCode')}}</button>
              <button type="button" width="122" class="captcha-btn" v-if="!isSendCode">{{sendMessage}} s</button>
            </div>
          </div>

          <div class="tab-box_item mt-40">
            <div class="box-name"></div>
            <div class="box-input">
              <!-- <el-checkbox v-model="checked">您已阅读并同意 <a href="javascript:void(0)">《用户授权协议》</a></el-checkbox> -->
            </div>
          </div>

          <div class="tab-box_item">
            <div class="box-name"></div>
            <div class="box-input">
              <button type="button" @click="forgot()">{{$t('common.login.resetPassword')}}</button>
            </div>
          </div>
          
      </div>
      </div>

      <div class="footer getFoot">
        <div class="container">
            <p>{{$t('common.foot.copy')}} <img src="../../../assets/images/public/icp.png" width="20" height="20" alt=""> {{$t('common.foot.copy1')}}110010000000000</p>
        </div>
      </div>
  </div>
</template>
<script>
import {ajax,showToast,jumpRout,showToastSuccess,reg} from '@/utils/js.js'
import {forgotPassword,getCode,checkName} from '@/services/api.js'
// const log = console.log
export default {
  data() {
    return {
      isSendCode:true,
      sendMessage:"60",
       radio: '2',
       checkStatus:2,
       info:{

       },
       user:{
         "code": "",
          "newPwd": "",
          "oldPwd": "",
          "phone": ""
       },
       haved:false
    }
  },
  mounted(){
    console.log(reg)
  },
  computed:{
   
  },
  watch:{
   
  },
  methods:{
    Content(url){
      jumpRout(this,url);
    },
    check(e){
      console.log(this.user.phone)
      if(this.user.phone.length==11){
        ajax(this,checkName,{
          loginName:'',
          phone:this.user.phone
        },res=>{
          // false=>存在，true=>不存在
          console.log(res)
          this.haved = res.data
        })
      }
      
      if(!reg.phone1.test(this.user.phone)){
        this.checkStatus=0;
      }else{
        this.checkStatus=2;
          // 获取找回密码信息
          // ajax(this,forgotPassword,this.user,res=>{
          //   this.identityPropertiesList=res.data;
          // })
      }
    },
    navTo(url){
      jumpRout(this,url);
    },
   forgot(){
     if(this.user.phone==""){
         showToast(this,this.$t('common.login.enterPhone'));
         return false;
     }
     if(this.user.newPwd==""){
         showToast(this,this.$t('common.login.enterNewPassword'));
         return false;
     }
     if(!reg.password.test(this.user.newPwd)){
          showToast(this,'密码输入格式不正确',0)
          return false;
      }
      if(this.user.code==""){
        showToast(this,this.$t('common.login.enterCode'));
         return false;

     }
      ajax(this,forgotPassword,this.user,res=>{
          console.log(res);
          showToast(this,res.msg,1)
          setTimeout(() => {
            this.$router.push('/login')
          }, 1500);
      },err=>{
        // showToast(this,err.msg)
      })
   },
   sendCode(){
       const TIME_COUNT = 60;
       if(this.user.phone.length != 11){
         showToast(this,this.$t('common.login.phoneErr'),1);
         return false;
       }
       if (!this.timer) {
        // 企业性质 corporateType
        ajax(this,getCode,{
          phone:this.user.phone,
          type:"ForgotPassword"
        },res=>{
           showToastSuccess(this,this.$t('common.login.getCodeOk'));
           this.sendMessage = TIME_COUNT;
           this.isSendCode = false;
           this.timer = setInterval(() => {
           if (this.sendMessage > 0 && this.sendMessage <= TIME_COUNT) {
             this.sendMessage--;
            } else {
             this.isSendCode = true;
             clearInterval(this.timer);
             this.timer = null;
            }
           }, 1000)
        },err=>{
          // showToast(this,err.msg)
        })
        
         
      }
    },
  }
}
</script>
<style lang="scss">
.register{
 .blue_color{
    color:#0f54bc;
  }
  .red_color{
    color:red;
  }
  *{
    margin: 0;
    padding:0;
  }
  .header{
    width: 100%;
    height:82px;
    background:rgba(255,255,255,1);
    opacity:1;
  }
  .require{
    color: red;
  }
  .container{
    width:1200px;
    height:82px;
    margin: 0 auto;
    box-sizing: border-box;
  }
  .header>.container{
    display: flex;
    flex-direction: column;
    justify-content: center;
  }
  .inbk{
    display: inline-block;
    vertical-align: middle;
  }
  .box{
    position: relative;
    box-sizing: border-box;
    width: 1200px;
    height:665px;
    background: #fff;
    margin: 10px auto 0 auto;
  }
  .tab{
    display: flex;
    flex-direction: row;
    justify-content: center;
    font-size:18px;
    font-family:MicrosoftYaHei;
    line-height:31px;
    color:rgba(51,51,51,1);
    opacity:1;
    padding-top: 78px;
    padding-bottom: 20px;
  }
  .mr-20{
    margin-right: 20px;
  }
  .ml-20{
    margin-left: 20px;
  }
  .tab-box{
    // margin-left: 300px;
  }
  .tab-box_item{
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    justify-content: flex-start;
    margin-top: 15px;
    align-items: center;
  }
  
.box-name{
    width: 130px;
    text-align: right;
    font-size:14px;
    font-family:MicrosoftYaHei;
    line-height:40px;
    color:rgba(102,102,102,1);
    -webkit-text-stroke:1 rgba(0,0,0,0.00);
    text-stroke:1 rgba(0,0,0,0.00);
    opacity:1;
  }
  .box-input p{
     margin-left: 5px;
    padding: 0 5px;
    line-height: 40px;
  }
   .box-input input{
     margin-left: 5px;
     padding: 0 5px;
     box-sizing: border-box;
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    justify-content: flex-start;
    width:365px;
    height:40px;
    background:rgba(255,255,255,1);
    border:1px solid rgba(230,226,226,1);
    opacity:1;
    border-radius:2px;
   
  }
  .captcha-input{
    float: left;
    width: 244px!important;
    box-sizing: border-box;
  }
  .captcha-btn{
    margin-left: 8px;
    float: right;
    width: 112px!important;
    font-size:14px;
    font-family:Microsoft YaHei;
    font-weight:400;
    line-height:40px;
    color:rgba(15,84,188,1)!important;
    -webkit-text-stroke:1 rgba(0,0,0,0.00);
    text-stroke:1 rgba(0,0,0,0.00);
    opacity:1;
    background:rgba(255,255,255,1)!important;
    border:1px solid rgba(15,84,188,1)!important;
    border-radius:2px!important;
  }
  .box-input a{
      color: #0F54BC;
  } 
  .box-input button{
      width:365px;
      height:40px;
      background:rgba(15,84,188,1);
      opacity:1;
      border-radius:2px;
      font-size:14px;
      font-family:Microsoft YaHei;
      font-weight:400;
      line-height:40px;
      color:rgba(255,255,255,1);
      -webkit-text-stroke:1 rgba(0,0,0,0.00);
      text-stroke:1 rgba(0,0,0,0.00);
      border: none;
      outline: none;
  }
  .mt-40{
    margin-top: 40px;
  }
  .box-des{
    font-size:12px;
    font-family:Microsoft YaHei;
    font-weight:400;
    line-height:16px;
    color:rgba(204,204,204,1);
    -webkit-text-stroke:1 rgba(0,0,0,0.00);
    text-stroke:1 rgba(0,0,0,0.00);
    opacity:1;
    margin-left: 5px;
  }
  .footer{
    text-align: center;
    width: 100%;
    height:84px;
    line-height: 84px;
    // border-top:1px dashed #000;
    // margin-top: 100px;
    font-size:12px;
    // background:rgba(255,255,255,1);
    opacity:1;
    font-size: 12px;
    font-family:Microsoft YaHei;
    font-weight:400;
    line-height:16px;
  }
  .footer p{
    line-height: 84px;
  }
  .footer p img{
    margin: 0px 5px;
    position: relative;
    top:5px;
  }
}

</style>